<?
	/**
	 * UCLibWebService.php
	 * WebService类
	 *
	 * Copyright (c) 2010 snda.com - Web Development Center
	 * @author: Gu Shougang <gushougang@snda.com>
	 */
	
	class UCLibWebService
	{
		# SOAP静态对象
		protected static $soapList = array();
		
		public static function getInstance($wsdl, $options = array(), &$message)
		{
			$key = md5($wsdl);
			if(!isset(self::$soapList[$key]))
			{
				if(!is_array($options))
				{
					$options = array();
				}
				try
				{
					self::$soapList[$key] = new SoapClient($wsdl, $options);
				}
				catch(SoapFault $fault)
				{
					$message = $fault->getMessage();
					return FALSE;
				}
			}
			
			return self::$soapList[$key];
		}
		
		public static function soapRequest($apiName, $apiParam, $wsdl, $options = array(), &$message)
		{
			if(!is_array($options))
			{
				$options = array();
			}
			try
			{
				$soap = self::getInstance($wsdl, $options, $message);
				if($soap === FALSE)
				{
					return FALSE;
				}
				
				$result = $soap->$apiName($apiParam);
			}
			catch(SoapFault $e)
			{
				$message = $e->getMessage();
				return FALSE;
			}
			
			return $result;
		}
	}
?>